package com.uobgroup.ews.uam.core.common;

import com.uobgroup.ews.uam.core.configuration.AppConfig;
import com.uobgroup.ews.uam.core.domain.SecurityGroup;
import com.uobgroup.ews.uam.core.domain.SecurityGroupAware;


public class SecurityGroupUtils {

   /**
    * Get the security group object from the input entity that implements the {@link SecurityGroupAware}
    * @author ndduy
    * @param entity {@link SecurityGroupAware}
    * @return {@link SecurityGroup}
    */
   public static SecurityGroup getSecurityGroup(SecurityGroupAware entity){
      SecurityGroup securityGroup = new SecurityGroup();
      securityGroup.setDisplayName(entity.getSecurityGroupName());
      if(securityGroup.getDisplayName() != null){
         if(securityGroup.getDisplayName().contains(" ")){
            securityGroup.setDisplayName(securityGroup.getDisplayName().replace(" ", "_").trim());
         }
      }
      securityGroup.setDN(AppConfig.getProperty(UMMConstants.LDAP_DN_GROUP_PREFIX + entity.getParentGroupName()));
      return securityGroup;
   }
}
